let info = document.querySelector('.info')
let couponid = getQueryString('couponid')

fetch(`http://chst.vip:1234/api/getcouponproduct?couponid=${couponid}`)
    .then(body => body.json())
    .then(res => {
        // console.log(res.result)
        let el = '';
        let str = ''

        res.result.forEach(item => {
            // console.log(item)
            el += `<li couponProductid=${item.couponProductId}>
        ${item.couponProductImg}
        <div class="infoR">
            <h4 class="title">${item.couponProductName}</h4>
            <div class="other">
                <h4 class="price">${item.couponProductPrice}</h4>
                <p class="term">${item.couponProductTime}</p>
            </div>
        </div>
    </li>`

            str += `<li class="lis">${item.couponProductImg}</li>`

        })
        info.innerHTML = el
        $('.uu').html(str)
    })

// 轮播图
let index = 0;
$('#rotaation').slideUp()
$('.info').on('click', 'li', function () {
    $('#rotaation').slideDown(200)
    // console.log($(this));
    index = $(this).attr('couponProductid')
    //   console.log(index);
    $('.uu').css('left', -index * $('.lis').width())
    console.log(-index * $('.lis').width())
})

$('.uls').on('click', 'p', function () {
    // console.log($(this));
    $('#rotaation').slideUp(200)
})
let al = document.querySelector('.arrow_l')
let ar = document.querySelector('.arrow_r')

al.onclick = function () {

  console.log(index);
  if (index > 0) {
    index--
    $('.uu').css('left', -index * $('.lis').width())
  } else {
    alert('这是第一张')
    return
  }
}

ar.onclick = function () {
  index++
  console.log(index);
  // console.log(index)
  $('.uu').css('left', -index * $('.lis').width())

}


// 返回顶部
let toTop = $('.gotop').get(0)
// console.log(toTop)

toTop.onclick = function (e) {
      console.log(123)
    document.documentElement.scrollTop = 0;
}